<#assign contextPath=springMacroRequestContext.getContextPath() />
<#import "/public/frame/main.html" as frame />
<@frame.head "南航明珠商城-系统管理">
</@frame.head>
<link rel="stylesheet" type="text/css" href="${contextPath}/resources/css/multi-select.css">
<div class="page-container">
	<form action="${contextPath}/user/user_update" method="post" class="form form-horizontal" id="form-user">
	<input type="hidden"  name="userId" id="userId" value="${(user.id?c)!}"/>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				机构名：</label>
			<div class="formControls col-xs-6 col-sm-6">
					           <span class="select-box radius">
	           <select class="select"  name="organizationId" id="organizationId">
	           <option value>请选择机构</option>
	             <#list organizationList as list>  
	                 <option value="${list.id?c}" <#if list.id==user.organizationID>selected="selected" </#if>>${list.name}</option>
	             </#list>
	           </select>
	           </span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				部门名：</label>
			<div class="formControls col-xs-6 col-sm-6">
					           <span class="select-box radius">
	           <select class="select"  name="departmentId" id="departmentId">
	           	 <#list departmentList as list>  
	                 <option value="${list.id?c}" <#if list.id==user.departmentID>selected="selected" </#if>>${list.name}</option>
	             </#list>
	           </select>
	           </span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				姓名：</label>
			<div class="formControls col-xs-6 col-sm-6">
					           <span class="select-box radius">
	           <select class="select"  name="emplyoeeId" id="emplyoeeId" >
	           <option value="">请先选择</option> 
	           <#list employeeList as list>  
	                 <option value="${list.id?c}" <#if list.id==user.employee.id>selected="selected" </#if>>${list.name}</option>
	             </#list>
	           </select>
	           </span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				登录名：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="${user.loginName}" placeholder="" id="loginName" name="loginName" >
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				密码：</label>
			<div class="formControls col-xs-6 col-sm-6">
			<input type="password" class="input-text"  name="password" value="" id="password" maxlength="16"></input>
				
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				重复密码：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="password" class="input-text"  name="repeatPwd" value="" id="repeatPwd" maxlength="16" autocomplete="off"></input>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				用户状态：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<span class="select-box radius">
	           <select class="select"  name="status" id="status">
		           	<#if user.status==1>
	            	<option value="1">可用</option> 
		           <option value="0">禁用</option> 
		           <#else>  
		             <option value="0">禁用</option> 
   	            	<option value="1">可用</option> 
				</#if> 
	           </select>
	           </span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				授权管理：</label>
			<div class="formControls col-xs-6 col-sm-6">
	
				  <select id='pre-selected-options' multiple='multiple' name="roleIdList" id="roleIdList" >
	             <#list roleList as list>  
	             
	             	<option value="${list.id?c}" <#if list.hasRole>selected </#if>>${list.name}</option>
	             </#list>
				  </select>
	           
			</div>
		</div>
				<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				
				</label>
			<div class="form-label col-xs-4 col-sm-2">
			非授权角色
			</div>
			<div class="form-label col-xs-4 col-sm-3">
			授权角色
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-2">
				<input class="btn btn-primary radius" type="button" onclick="update();"  value="&nbsp;&nbsp;修改&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</div>
<@frame.end "default">
</@frame.end>
<script type="text/javascript" src="${contextPath}/resources/lib/My97DatePicker/4.8/WdatePicker.js"></script>
  <!-- Bootstrap JavaScript -->
<script src="${contextPath}/resources/js/bootstrap.min.js"></script>
<script src="${contextPath}/resources/js/jquery.multi-select.js"></script>
		<script type="text/javascript"
			src="${contextPath}/resources/js/system/ckeditor.js"></script>
		<script type="text/javascript"
			src="${contextPath}/resources/js/system/easyPwd.js"></script>
<script type="text/javascript">
var path="${contextPath}";
$('#pre-selected-options').multiSelect();
$(document).ready(function(){
    //顶级分类方法
  $("#organizationId").change(function(){
	   
	           $("#departmentId").removeAttr("disabled");
	           		var id = $('#organizationId').val();
	           		if(id == 0){
		           		$("#departmentId").attr("disabled", "disabled");
		           	  	$("#departmentId").empty();
		           	 	$("#departmentId").prepend("<option value='-1'>请先选择部门</option>");
		           	 	return false;
	           		}
	           		  var url=path+"/employee/query_department_list?id="+id;
			           $.post(url,'',function(msg){
				           if(msg!="notfound")
				           {  
						     $("#departmentId").html(msg);    
				           }
			          });
	            });
});
//表单提交;

function checkForm(){
  	
	var dept=document.getElementById("departmentId").value;
	var selectOrg=document.getElementById("organizationId").value;
	var selectRole=document.getElementById("pre-selected-options").value;
 	var emp=document.getElementById("emplyoeeId").value;
  	var loginname=document.getElementById("loginName").value;
  	var password=document.getElementById("password").value;
  	var repeatPwd=document.getElementById("repeatPwd").value
	var txt = /^[A-Za-z0-9]+$/;

		if(selectOrg==-1){
			layer.alert("请选择机构");
        return false;
		}
	if(dept==-1){
		layer.alert("请选择部门！");
        return false;
	}
	if(emp==0){
		layer.alert("请选择您要添加角色的员工姓名");
        return false;
	}
	 if(loginname.length==0){
		 layer.alert("请填写您的登录名");
        return false;
	 }
	 if(loginname.match(txt)==null){ 
		 layer.alert("用户名只能包含数字字母！");
        return false;
	 }
	  if(password.length==0){
		  layer.alert("请填写密码！");
            return false;
	  }
	  
	  if(password.length < 8 || password.length > 20){
		  layer.alert("密码长度要求为8-20位！");
          return false;
	  }
	  
	  if(repeatPwd != password){
		  layer.alert("两次密码输入不一致，请重新输入！");
          return false;
	  }
	  if(selectRole.length==0){
		  layer.alert("请选择角色");
            return false;
	  }
	  return true;
}
function update(){

	var loginname=document.getElementById("loginName").value;
	
	if(checkForm()){
	
	
	    $("#form-user").ajaxSubmit({
			dataType : 'html',
	        success: function(message){
	        		if(message == "200"){
	                    layer.msg('操作成功!',{icon:1,time:1000},function(){
	/*                         var index = parent.layer.getFrameIndex(window.name);
	                        parent.query_brand_form.submit();
	                        parent.layer.close(index); */
	                        parent.window.location.reload();
	                    });
	 				}else if(message == "500"){
	 					layer.alert("系统繁忙！");
	 				}else{
	 					layer.alert(message);
	 				}
	        },
	        error: function(){
	            layer.msg('操作失败!',{icon:5,time:1000});
	        }
	    });
	}
}
function trim(str){ 
	 return str.replace(/(^\s*)|(\s*$)/g, "");
	}
</script>
</body>
</html>